Integrate with Machine Learning APIsExtract, Analyze, and Translate Text from Images with the Cloud ML APIs在Cloud Console中,依序點選
Navigation Menu > APIs & services > Credentials
按 + Create Credentials > 下拉選單選 API key
Copy key 後按Close
把Key加入環境變數
export API_KEY=<YOUR_API_KEY>


image to a cloud storage bucketimage: sign.jpg 為偵測目標




{
"requests": [
{
"image": {
"source": {
"gcsImageUri": "gs://my-bucket-name/sign.jpeg"
}
},
"features": [
{
"type": "TEXT_DETECTION",
"maxResults": 10
}
]
}
]
}

在Cloud shell中,使用curl call the Vision API
curl -s -X POST -H "Content-Type: application/json" --data-binary @ocr-request.json https://vision.googleapis.com/v1/images:annotate?key=${API_KEY}
可以看到:
[更正-my bucket name為project id]


由於輸出太長,可以輸出到文字檔內



上傳圖片到Cloud Storage,
使用Vision API擷取文字,
將擷取出來的文字存到文字檔(.json),
接著使用Translation API可以知道是哪國語言,
並翻譯成target(範例為en:english),
同樣地把翻譯好的結果存在文字檔,
建立Natural Language API 的request JSON檔,
將翻譯好的存檔輸入剛建的request,
再call api得每個word的分析(分類)。